<template>
	<view class="bg-white px-2 py-5 position-relative" v-if="detail">
		<view class="font-weight text-danger font-md">{{detail.jqbzSettings.name}}</view>
		<view class="fn-26 cgMaterial pb-2">
			<view ><text>部件编码：</text><text>{{detail.jqbzSettings.code}}</text></view>
			<view v-if="detail.batch"><text>批号：</text><text>{{detail.batch}}</text></view>
			<view v-if="detail.code"><text>编码：</text><text>{{detail.code}}</text></view>
			<view class="text-orange"  v-if="detail.remain"><text>库存：</text><text>{{detail.remain}}</text></view>
			<view>发货数量：{{detail.nums}}</view>
			<view class="tag position-absolute bg-info text-white py-1 px-2" v-if="detail.shCustomerInfo">{{detail.shCustomerInfo.name}}</view>
		</view>
		
		 <!-- 签收详情 -->
		<view class="border-dashed-top py-2" v-if="detail.isSign===1">
			<view><text>签收数量：</text><text>{{detail.autNums}}</text></view>
			<view><text>签收人：</text><text >{{detail.signerName}}</text></view>
			<view><text>签收时间：</text><text>{{detail.signTime}}</text></view>
		</view>
		<!-- 创建详情 -->
		<view class="border-dashed-top font-sm text-light-muted py-2">
			<view>创建者：{{detail.creatorName}}</view>
			<view>创建时间：{{detail.createTime}}</view>
		</view>
		<view class="pt-2 d-flex j-end border-dashed-top">
			<view class="border main-rounded-circle border-orange text-orange px-2" @click="optionHandle(detail,'sign')" v-if="jzUser&&!detail.isSign">签收</view>
		</view>
	</view>
</template>

<script>
	import api from '@/common/api/api.js'
	export default {
		data() {
			return {
				id: '',
				detail: null,
				jzUser:false
			}
		},
		onLoad(e){
			this.id = e.id
			this.getDetail()
			this.jzUser = uni.getStorageSync('role').findIndex((item,index)=>item.name==='jz_user')!==-1
		},
		methods: {
			getDetail(){
				let self = this;
				self.$H.get(api.partsDetail+this.id).then(res=>{
					self.detail = res.content
				})
			},
			optionHandle(item,type){
				let self = this;
				switch(type){
					case 'sign':
					uni.showModal({
					    title: '提示',
					    content: '是否确认签收',
					    success: function (res) {
					        if (res.confirm) {
								self.$H.post(api.updateParts,{
									id: item.id,
									isSign:1
								}).then(res=>{
									uni.showToast({
									    title: '签收成功',
										 icon: 'success',
									    duration: 2000
									});
									self.getDetail()
								})
					        } else if (res.cancel) {
					            console.log('用户点击取消');
					        }
					    }
					});
					break
				}
			}
		}
	}
</script>

<style scoped>
.tag{
	right:0upx;
	top:0;
	border-bottom-left-radius:26upx;
}
</style>
